#pragma once

#include <sys/ptrace.h>
#include <sys/user.h>
#include <signal.h>

typedef int (* handle_input) (pid_t pid
                              , struct  user_regs_struct * regsisters
                              , void ** text
                              , long *  text_size
                              , long *  text_addr
                              , void ** data
                              , long *  data_size
                              , void *  filter_context
                              );

typedef void * (* create_filter_context) (const char * arg);
typedef void   (* free_filter_context)   (void * context);

struct provide
{
    handle_input          filter;
    create_filter_context constructor;
    free_filter_context   destructor;
};

struct filter
{
    const struct provide * provide;
    void                 * handle;
    void                 * context;
};


typedef const struct provide * (* filter_init)(void);

#define PROVIDE_FUNCTION_MASK "%s_init"

struct filter * open_filter(const char * name
                            , const char * argv
                            );

void close_filter(struct filter * filter);
int  apply_filter(pid_t pid
                  , struct  user_regs_struct * regsisters
                  , void * text
                  , long * text_size
                  , long * text_addr
                  , void * data
                  , long * data_size
                  , struct filter * filter
                  );

#define FILTER_PREFIX "cfd-"
